import React, { useEffect } from "react";
import { useLocation, Navigate } from "react-router-dom";

export const withLogin = (Comp) => {
  return () => {
    // 逻辑
    const token = localStorage.getItem("token");
    const { pathname } = useLocation();

    //  未登录  &&  访问的页面不是登录
    if (!token && pathname !== "/login") {
      return <Navigate to="/login"></Navigate>;
    }

    return <Comp></Comp>;
  };
};
